package EXam.Question15;

public class Student666 implements Comparable<Student666> {
    private String name;
    private int physic;
    private int chemistry;
    
    // 空参构造方法
    public Student666() {
    }
    
    // 带参构造方法
    public Student666(String name, int physic, int chemistry) {
        this.name = name;
        this.physic = physic;
        this.chemistry = chemistry;
    }
    
    // getter和setter方法
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public int getPhysic() {
        return physic;
    }
    
    public void setPhysic(int physic) {
        this.physic = physic;
    }
    
    public int getChemistry() {
        return chemistry;
    }
    
    public void setChemistry(int chemistry) {
        this.chemistry = chemistry;
    }
    
    // 计算总分的方法
    public int getTotalScore() {
        return physic + chemistry;
    }
    
    // 重写toString方法
    @Override
    public String toString() {
        return "Student666{name='" + name + "', physic=" + physic + ", chemistry=" + chemistry + ", total=" + getTotalScore() + "}";
    }
    
    // 实现compareTo方法，用于TreeSet排序
    @Override
    public int compareTo(Student666 other) {
        // 按总分从高到低排序（主要条件）
        int totalScoreDiff = other.getTotalScore() - this.getTotalScore();
        if (totalScoreDiff != 0) {
            return totalScoreDiff;
        }
       // System.out.println("===============");
        // 总分相同时，按物理成绩从高到低排序（次要条件）
        return this.getPhysic() - other.getPhysic();
    }
}